import { Controller, Body, Get, Post, Session, UseInterceptor, UseBefore, Param,Req, Res,Ctx } from "routing-controllers";
import { CheckLoginMiddleware } from "../../middleware/CheckLoginMiddleware";
import { Service, Inject } from "typedi";
import { CarServiceImpl } from "../../service/impl/CarServiceImpl";
import { config } from "../../config";
import { JsonResponseMiddlewares } from "../../middleware/JsonResponseMiddlewares";

@Service()
@Controller(`${config.apiurl}/car`)
@UseInterceptor(JsonResponseMiddlewares)
export class CarController {
	
	@Inject()
	private carServiceImpl: CarServiceImpl;
	
	/**
	 * 删除购物车课程
	 * @param session
	 * @param params
	 */
	@Post("/deleteCar")
	public async deleteCar(@Session() session,
	                       @Body() params: Object) {
		
		return await this.carServiceImpl.deleteCar(params['userid'], params['courseid'])
	}
	
	/**
	 * 添加购物车课程
	 * @param session
	 * @param params
	 */
	@Post("/addCourseToCart")
	public async addCourseToCart(@Body() params: Object) {
		return await this.carServiceImpl.addCar(params['userid'], params['courseid'])
	}
}